package com.beauty.dressing.module.market.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.xiaolanba.commonlib.fresco.FrescoUtil;
import com.beauty.dressing.common.base.BaseRecyclerViewHolder;
import com.beauty.dressing.common.bean.BaseBean;
import com.beauty.dressing.common.bean.LeaseItem;
import com.beauty.dressing.common.bean.LeaseItemDetail;
import com.beauty.dressing.common.bean.SaleItem;
import com.beauty.dressing.common.bean.SaleItemDetail;
import com.beauty.dressing.common.bean.ShowItem;
import com.beauty.dressing.rxandroid.api.ApiManager;
import com.beauty.dressing.R;

/**
 * 类描述
 *
 * @author xutingz
 * @email：914603097@qq.com
 */
public class ShopHeaderHolder extends BaseRecyclerViewHolder<BaseBean> {
    private TextView mShopTitle,mPriceTxt;
    private TextView mPriceTitle,mDepositTitle,mDepositPrice,mOilTitle,mOilPrice;
    private SimpleDraweeView mTopImg;

    public ShopHeaderHolder(Context context, LayoutInflater inflater, ViewGroup viewGroup) {
        super(R.layout.shop_detail_header, context, inflater, viewGroup);
    }

    @Override
    public void findView() {
        mTopImg = (SimpleDraweeView) itemView.findViewById(R.id.top_img);
        mShopTitle = (TextView) itemView.findViewById(R.id.shop_title);
        mPriceTxt = (TextView) itemView.findViewById(R.id.price_txt);
        mPriceTitle = (TextView) itemView.findViewById(R.id.price_title);
        mDepositTitle = (TextView) itemView.findViewById(R.id.deposit_title);
        mDepositPrice = (TextView) itemView.findViewById(R.id.deposit_price);
        mOilTitle = (TextView) itemView.findViewById(R.id.oil_title);
        mOilPrice = (TextView) itemView.findViewById(R.id.oil_price);
    }

    @Override
    public void bindData(BaseBean bean, int position) {
        if (bean instanceof LeaseItemDetail){
            LeaseItemDetail leaseItem = (LeaseItemDetail) bean;
            loadImage(leaseItem.image);
            showTitle(leaseItem.lease_name);
            showPrice(leaseItem.price,leaseItem.time_type);
            mPriceTitle.setText("设备租金");
            mDepositTitle.setText("设备押金");
            mDepositPrice.setText(leaseItem.deposit);
            mOilTitle.setText("烟油价格");
            mOilPrice.setText(leaseItem.pricel);
        } else if (bean instanceof SaleItemDetail){
            SaleItemDetail saleItem = (SaleItemDetail) bean;
            loadImage(saleItem.image);
            showTitle(saleItem.sales_name);
            showPrice(saleItem.price,null);
        }
    }

    private void loadImage(String url){
        FrescoUtil.loadImage(mTopImg, ApiManager.HEAR_URL+url);
    }

    private void showTitle(String title){
        mShopTitle.setText(title);
    }

    private void showPrice(String price,String time_type){
        if (TextUtils.isEmpty(time_type)){
            mPriceTxt.setText("¥"+String.valueOf(price));
        } else {
            mPriceTxt.setText("¥"+String.valueOf(price)+"/"+time_type);
        }
    }
}
